package com.tcxhb.job.core.service.job.impl;

import com.tcxhb.job.dao.dataobject.JobAppDO;
import com.tcxhb.job.dao.dataobject.query.JobAppQuery;
import com.tcxhb.job.dao.repository.JobAppRepository;
import com.tcxhb.job.core.service.job.JobAppService;
import com.tcxhb.job.common.model.PageResponse;
import com.tcxhb.job.common.utils.ParamUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * author:auto.generator
 * time: 2023-11-02
 */
@Service
public class JobAppServiceImpl implements JobAppService {
    @Resource
    private JobAppRepository repository;

    @Override
    public Long create(JobAppDO jobAppDO) {
        String uuid = UUID.randomUUID().toString();
        String secret = uuid.replace("-", "");
        jobAppDO.setAppsecret(secret);
        return repository.create(jobAppDO);
    }

    @Override
    public boolean deleteById(Long id) {
        ParamUtils.notNull(id, "id不能为空");
        return repository.deleteById(id);
    }

    @Override
    public boolean updateById(JobAppDO wjApp) {
        return repository.updateById(wjApp);
    }

    @Override
    public JobAppDO queryById(Long id) {
        ParamUtils.notNull(id, "id不能为空");
        return repository.queryById(id);
    }

    @Override
    public PageResponse<JobAppDO> page(JobAppQuery query) {
        return repository.page(query);
    }

    @Override
    public List<JobAppDO> list(JobAppQuery query) {
        return repository.list(query);
    }

    @Override
    public JobAppDO queryByApp(String appname) {
        JobAppQuery query = new JobAppQuery();
        query.setAppName(appname);
        List<JobAppDO> list = repository.list(query);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }
}
